import dashscope
from http import HTTPStatus


def call_with_messages(origin_sentence):
    messages = [{'role': 'system', 'content': '你需要理解我说的话并换个表达方式复述一遍，复述字数一定不能少于原句，直接回答复述的句子就可以了'},
                {'role': 'user',
                 'content': origin_sentence}]

    response = dashscope.Generation.call(
        dashscope.Generation.Models.qwen_plus,
        messages=messages,
        api_key='sk-cd0a7b8991f141ea86491a454247a232',
        result_format='message',  # set the result to be "message" format.
    )
    if response.status_code == HTTPStatus.OK:
        return response['output']['choices'][0]['message']['content']
    else:
        print('Request id: %s, Status code: %s, error code: %s, error message: %s' % (
            response.request_id, response.status_code,
            response.code, response.message
        ))
        return response.message


if __name__ == '__main__':
    print(call_with_messages('这些结果提示，植物激素的不平衡分布可能是果瘤形成的关键因素之一，尤其是细胞分裂素和其他促进生长的激素的协同作用可能在其中发挥了重要作用'))
